package com.imcoke.abchat.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author ccoke
 * @Description 一些转换工具
 * @Date: 11:19 2017-10-31
 */
public class CommonUtil {
    /**
     * @Author ccoke
     * @Description  将Date转换成String
     */
    public static String Date2String(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        return sdf.format(date);
    }

    /**
     * @Author ccoke
     * @Description 获取首字母或汉字
     */
    public static String getCharByString(String strId){
        String CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        //如果为空，则随机个字母
        if (strId == null){
            return String.valueOf(CHARS.charAt((int)(Math.random() * 26)));
        }
        char[] chars = strId.toCharArray();
        if(chars.length>0){
            char c=chars[0];
            if(Character.isLetter(c)){
                //是字母
                if(Character.isLowerCase(c)){
                    //是否是小写字母
                    c=Character.toUpperCase(c);
                    return String.valueOf(c);
                }else {
                    return String.valueOf(c);
                }
            }else{
                //不是字母返回
                return String.valueOf(c);
            }
        }
        return String.valueOf(CHARS.charAt((int)(Math.random() * 26)));
    }
}
